<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>教室管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <!-- 左树 -->
        <div class="layui-col-sm12 layui-col-md4 layui-col-lg2">
            <div class="layui-card" style="overflow: auto;">
                <ul id="ltTree" class="dtree" data-id="0"></ul>
            </div>
        </div>
        <!-- 右表 -->
        <div class="layui-col-sm12 layui-col-md8 layui-col-lg10">
            <div class="layui-card">
                <div class="layui-card-body">

                    <div class="layui-form toolbar">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label w-auto">搜索：</label>
                                <div class="layui-input-inline mr0">
                                    <input id="edtSearch" class="layui-input" type="text" placeholder="输入关键字"/>
                                </div>
                            </div>
                            <div class="layui-inline" >
                                <button class="layui-btn icon-btn" id="btnSearchByCode">
                                    <i class="layui-icon">&#xe615;</i>字典编码搜索
                                </button>
                                <button class="layui-btn icon-btn" id="btnSearchByName">
                                    <i class="layui-icon">&#xe615;</i>字典值搜索
                                </button>
                            </div>
                            <div class="layui-inline">

                                <button id="btnAdd" class="layui-btn icon-btn"  >
                                    <i class="layui-icon">&#xe654;</i>新增
                                </button>
                                <button id="btnDel" class="layui-btn layui-btn-danger icon-btn"  >
                                    <i class="layui-icon">&#xe640;</i>删除
                                </button>
                            </div>
                        </div>
                    </div>

                    <table class="layui-table" id="rtTable" lay-filter="rtTable"></table>

                </div>
            </div>
        </div>

    </div>
</div>

<script type="text/html" id="tool-table-bar">
    <a class="layui-btn layui-btn-xs layui-btn-radius" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del">删除</a>
</script>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery.form/4.3.0/jquery.form.min.js"></script>


<link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css">
<script type="text/javascript" src="../lib/layui-v2.6.3/layui.js"></script>

<link rel="stylesheet" href="../js/lay-module/dtree/dtree.css">
<link rel="stylesheet" href="../js/lay-module/dtree/font/dtreefont.css">

<script th:inline="javascript" type="application/javascript">

    layui.extend({
        dtree: '{/}../js/lay-module/dtree/dtree'
    })
    layui.use(['element','layer', 'table', 'code' ,'util', 'dtree', 'form'], function () {
        var element = layui.element,
            layer = layui.layer,
            table = layui.table,
            util = layui.util,
            dtree = layui.dtree,
            form = layui.form,
            $ = layui.$;

        // 树形渲染
        dtree.render({
            elem: '#ltTree',
            url: '/subject/leftMenu',//
            method: 'GET',
            dataStyle: "layuiStyle",  //使用layui风格的数据格式
            dataFormat: "list",  //配置data的风格为list
            // initLevel: '1',//默认展开层级，当该值大于level时，则会展开树的节点，直到不大于当前待展开节点的level
            response:{message:"msg",statusCode:0},  //修改 response中返回数据的定义
            ficon: [1,-1],
            icon: "2",  //修改二级图标样式

        });

        // 树形点击事件
        dtree.on('node("ltTree")', function (obj) {
            var data = obj.param;
            layer.msg('你选择了：' + JSON.stringify(data));
            //table.reload('rtTable', {where: {nodeId: data.nodeId}});
            ins1(data.nodeId,"",data.context);
        });

        // 渲染表格
        var ins1 = function (pid,cloumn,Keyword){
            table.render({
                elem: '#rtTable',
                url: '/subject/lists',
                cols: [
                    [
                        {type: 'checkbox'},
                        {field: 'id', align: 'center', sort: true, title: '科目Id'},
                        {field: 'subjectCode', align: 'center', sort: true, title: '学科代号'},
                        {field: 'subjectName', align: 'center', sort: true, title: '学科名称'},
                        {field: 'collegeName', align: 'center', sort: true, title: '院系名称'},
                        {field: 'majorName', align: 'center', sort: true, title: '专业名称'},
                        {field: 'subjectType', align: 'center', sort: true, title: '科目类型'},
                        {field: 'classroomType', align: 'center', sort: true, title: '使用教室类型'},
                        {field: 'releaseTime', align: 'center', sort: true, title: '创建时间'},
                        {field: 'modifyTime', align: 'center', sort: true, title: '修改时间'},
                        {field: 'status', align: 'center', sort: true, title: '状态'},
                        {align: 'center', align: 'center', toolbar: '#tool-table-bar', title: '操作', minWidth: 120}
                    ]],
                page: true,
                cellMinWidth: 100,
                where: {keyword:Keyword}   // 提交的参数
            });
        }

        ins1("","","");
        // 监听工具条
        table.on('tool(rtTable)', function (obj) {
            var data = obj.data; //获得当前行数据
            console.log(data);
            var layEvent = obj.event; //获得 lay-event 对应的值

            if (layEvent === 'edit') { // 编辑
                // showEditModel(data);
                layer.msg('点击了编辑');
                console.log(JSON.stringify(data))
                // 显示编辑表单
                var index = layer.open({
                    title: '编辑数据',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/subject/edit?id=' + data.id,
                    end: function(){
                        window.location.reload();
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (layEvent === 'del') { // 删除
                var deleteData = new Array();
                deleteData.push(data.dictId);
                deleteDictionary(deleteData);
                layer.msg('点击了删除');
            }
        });

        // 增加
        $('#btnAdd').click(function () {
            layer.msg("添加按钮");
            var index = layer.open({
                title: '添加数据',
                type: 2,
                shade: 0.2,
                maxmin:true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: '/subject/add',
                end: function(){
                    window.location.reload();
                }
            });
            $(window).on("resize", function () {
                layer.full(index);
            });
        });

        // 批量删除
        $('#btnDel').click(function () {
            var checkRows = table.checkStatus('rtTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要删除的数据', {icon: 2});
            } else {
                var deletedata = [];
                for(var i=0;i<checkRows.data.length;i++){
                    deletedata.push(checkRows.data[i].dictId);
                }
                deleteDictionary(deletedata);
            }
        });

        // 搜索按钮点击事件
        $('#btnSearchByCode').click(function () {
            var value = $('#edtSearch').val();
            ins1("","dict_code",value);
        });

        // 搜索按钮点击事件
        $('#btnSearchByName').click(function () {
            var value = $('#edtSearch').val();
            ins1("","dict_name",value);
        });

    });

</script>

</body>
</html>